

<template>

  <div>
     
     <div style="margin: 0.6rem; margin-bottom: 0;border-bottom: 1px #cfcfcf solid;" v-for="(item,index) in list">
       <div style="font-size: 1rem;margin-top: 1rem;">{{item.title}}</div>
       <div class="flex-row" style="justify-content: space-between; margin-top: 0.1rem">
         <div style="margin-top: 0.8rem;font-size: 0.9rem;color: #7b7a7a">{{item.name}}  第{{item.stage}}课</div>
         <div @click="change(index)">
         	<i class="iconfont icon-xinheart118 normal"></i>
         </div>
       </div>
     </div>
     <!--<div style="width: 100%; height: 0.01rem; background-color: #e4e4e5; border-top:1px #cfcfcf solid;"></div>-->

    <div v-if="list.length == 0" style="margin: 1rem auto; width: 50%; text-align: center; color:#7b7a7a ">暂无更多内容！</div>

  </div>

  
</template>

<script>
import { base64} from 'vux'
export default {

  components: {
   base64
  },
  data () {
    return {
    
      access_token:'',
      list:''
    
    }
  },
  methods:{
     
     
     
     
     //获取详情
    getDetail(){
    	
	    	this.$store.commit('updateLoadingStatus',true);
	    	
	    	this.$http.get(this.$store.state.api + 'index/collection-list&access_token=' + this.access_token)
		    .then((response) => {
		    		
		    console.log(response)
				
				if(response.body.code == 0) {
					
					this.list = response.body.data
					
				} else {
					
				}
					
				
				this.$store.commit('updateLoadingStatus',false);	
				
			}, (response) => {
	             
	            
	            
			});
    
    },
    
    
    //改变是否收藏
     change(index){
        console.log(index)
        
        
		    	
		    	this.$store.commit('updateLoadingStatus',true);
		    	
		    	this.$http.post(this.$store.state.api + 'index/user-collection',
		    	{
		    		access_token:this.access_token,
		    		section_id:this.list[index].section_id,
		    	})
		    	.then((response) => {
		    		
		    		console.log(response)
				
				if(response.body.code == 0) {
					
					this.getDetail()
					
//					this.message = response.body.msg
//				    this.showPositionValue = true
//					
					
				} else {
					
				}
				
				this.$store.commit('updateLoadingStatus',false);
					
				
				}, (response) => {
	                 
	                 
				});

     },
     
     //获取地址栏信息
		getUrlStr(name){
	      let reg = new RegExp("(^|\\?|&)" + name + "=([^&]*)(\\s|&|$)","i");
	      if(reg.test(window.location.href)){
	        return unescape(RegExp.$2.replace(/\+/g," "))
	      }
	      return undefined
	    },	
    
  },
  
  mounted() {
  	
  	var access_token = this.getUrlStr('access_token');
           var parentId = this.getUrlStr('parent_id');
           
            if(parentId == undefined){
              parentId = 0;
           }
           
           var uid = this.getUrlStr('uid');
           
           console.log(parentId.toString().indexOf('?'));
           
           if(parentId.toString().indexOf('?') > 0){
           	 parentId = parentId.split('?')[0];
           }
           
           
//         var uid = this.getUrlStr('uid');

           var locurl = location.href;
           locurl = base64.encode(locurl.split('?')[0]);
//		   locurl = locurl.replace(/\//g, "@@");
           
           console.log('-1-'+access_token)
           console.log('-2-'+parentId)
           console.log('-4-'+uid)
          
          
       
           if(access_token != undefined){
         
              localStorage.setItem("access_token",access_token); 
              localStorage.setItem("parent_id",this.getUrlStr('uid'));


           }
           
           console.log('-3-'+localStorage.getItem('access_token'));
           
            if(localStorage.getItem('access_token') != null){
         
              this.$root.registerjudge();
              this.$root.getShare();
              
            }else{
            	
            	console.log(222);
        	  this.$root.gotoWechat(locurl,parentId);
            }
           
       
         
    	   this.access_token = localStorage.getItem('access_token');

    this.getDetail();

  },
  
  


}



</script>


<style lang="less" scoped>
  
  .normal{
    font-size: 2rem;color:#a2a2a2
  }
  .active1{
    color: #ff9612 !important;
  }


</style>
